/**
 * 内在缓冲池.
 * 需要设计一定的释放规则.
 */
export default class MemoryCache {
    public static readonly instance = new MemoryCache();
    private readonly cache: { [key: string]: any; } = {};

    public put(key: string, obj: any) {
        if (!key || !obj) {
            console.warn("你缓存了一个空对象:", key, obj);
            return;
        }
        this.cache[key] = obj;
    }

    public get<T>(key: string, def?: T): T {
        if (!key) {
            console.error("MemoryCache key ==null");
            return;
        }
        return this.cache[key] ? this.cache[key] : def;
    }

    private release() {

    }
}

class ObjRef {
    public readonly obj: any;
    public ts: number;

    constructor(obj: any) {
        this.obj = obj;
        this.ts = Date.now();
    }
}
